/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef INCLUDE_VBS_TRANSPORT_UDSSTREAMTRANSPORTDESCRIPTOR_H_
#define INCLUDE_VBS_TRANSPORT_UDSSTREAMTRANSPORTDESCRIPTOR_H_

#include <transport/TCPHeader.hpp>
#include <iostream>
#include <ertps/ertps_dll.h>
#include <transport/TransportDescriptorInterface.h>
#include <cstdint>
#include <vector>
#include <string>

namespace vbs {
namespace transport {

struct UDSStreamTransportDescriptor : public TransportDescriptorInterface {

    uint32_t sendBufferSize;

    uint32_t receiveBufferSize;

    std::vector<std::string> listening_paths;

    RTCPHeader rtcp_header_;

    //! Add listener port to the listening_paths list
    void add_listener_path(std::string path) { listening_paths.push_back(path); }

    void set_rtcp_header(const RTCPHeader& rtcp_header) { rtcp_header_ = rtcp_header; }

    uint32_t min_send_buffer_size() const override { return sendBufferSize; }

    //! Constructor
    RTPS_DllAPI UDSStreamTransportDescriptor()
        : TransportDescriptorInterface(65500U, 1), sendBufferSize(65535U), receiveBufferSize(65535U) {}

    //! Copy constructor
    RTPS_DllAPI UDSStreamTransportDescriptor(const UDSStreamTransportDescriptor& t)
        : TransportDescriptorInterface(t),
          sendBufferSize(t.sendBufferSize),
          receiveBufferSize(t.receiveBufferSize),
          listening_paths(t.listening_paths),
          rtcp_header_(t.rtcp_header_) {}

    //! Copy assignment
    RTPS_DllAPI UDSStreamTransportDescriptor& operator=(const UDSStreamTransportDescriptor& t) {
        TransportDescriptorInterface::operator=(t);
        sendBufferSize = t.sendBufferSize;
        receiveBufferSize = t.receiveBufferSize;
        listening_paths = t.listening_paths;
        rtcp_header_ = t.rtcp_header_;
        return *this;
    }

    //! Comparison operator
    RTPS_DllAPI bool operator==(const UDSStreamTransportDescriptor& t) const {
        return (TransportDescriptorInterface::operator==(t) && (this->sendBufferSize == t.sendBufferSize) &&
                (this->receiveBufferSize == t.receiveBufferSize) && (this->listening_paths == t.listening_paths) &&
                (this->rtcp_header_ == t.rtcp_header_));
    }

    //! Destructor
    virtual ~UDSStreamTransportDescriptor() = default;

    TransmitorType get_type() const override;

    TransportInterface* create_transport() const override;
};

}  // namespace transport
}  // namespace vbs

#endif  // INCLUDE_VBS_TRANSPORT_UDSSTREAMTRANSPORTDESCRIPTOR_H_
